package com.xxcxcxcx.xc_crop.common.blocks.crops.minecraft.melon;

import com.xxcxcxcx.xc_crop.common.Configuration;
import com.xxcxcxcx.xc_crop.common.ReadConfig;
import net.minecraft.core.BlockPos;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.block.AttachedStemBlock;
import net.minecraft.world.level.block.StemGrownBlock;
import net.minecraft.world.level.block.state.BlockState;

import java.util.ArrayList;
import java.util.function.Supplier;

public class MelonAttachedStemBlockChange extends AttachedStemBlock implements ReadConfig {
    public MelonAttachedStemBlockChange(StemGrownBlock p_152060_, Supplier<Item> p_152061_, Properties p_152062_) {
        super(p_152060_, p_152061_, p_152062_);
    }
    public static String ConfigKey = "Melon";
    protected static ArrayList<String> biomeWhiteList = new ArrayList<>();
    protected static boolean whitelistRead = false;//保证config只读一次
    public boolean canBiome(BlockPos pos,LevelReader levelReader){
        Biome.BiomeCategory currentBiome = Biome.getBiomeCategory(levelReader.getBiome(pos));
        if(!whitelistRead)ReadConfigMessage();
        return biomeWhiteList.isEmpty()||biomeWhiteList.contains(currentBiome.getName());
    }
    public void ReadConfigMessage(){
        biomeWhiteList = Configuration.whitelistStrtoArraylist(Configuration.Config.get(ConfigKey));
        whitelistRead = true;
    }
    public boolean canSurvive(BlockState p_52282_, LevelReader p_52283_, BlockPos p_52284_) {
        return canBiome(p_52284_,p_52283_) && p_52283_.canSeeSky(p_52284_) && super.canSurvive(p_52282_, p_52283_, p_52284_);
    }
}
